<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>选择文件上传</title>


    <style>
        .btn-select-img {
            width: 100px;
            height: 100px;
            font-size: 50px;
            line-height: 100px;
            position: relative;
            border: 1px solid #cccccc;
            text-align: center;
            color: #737373;
        }

        .btn-select-img::before {
            content: "+";
            width: 100%;
            height: 100%;
        }

        .btn-select-img > input[type='file'] {
            position: absolute;
            width: 100%;
            height: 100%;
            left: 0;
            top: 0;
            opacity: 0;
        }

        .image-container > img {
            width: 100px;
            height: 100px;
            vertical-align: middle;
        }

        .image-container > img + img {
            margin-left: 5px;
        }
    </style>
</head>
<body>

<div class="image-container">

</div>

<div class="btn-select-img">
    <input type="file" accept="image/jpeg,image/jpg,image/png">
</div>
<script src="../../libs/jquery3_1_1.min.js"></script>
<script>
    $(function () {
        var imgs = [];
        $('.btn-select-img > input[type="file"]').on('change', function (e) {
            var files = e.currentTarget.files;
            if (files[0]) {
                imgs.push(files[0]);
            }
            refreshImgContainer();
        });


        function refreshImgContainer() {
            var html = '';
            for (var i = 0; i < imgs.length; i++) {
                var file = imgs[i];
                html += '<img src="'+getObjectURL(file)+'"/>';
            }

            $('.image-container').html(html);
        }

        function getObjectURL(file) {
            var url = null;
            if (window.createObjectURL != undefined) { // basic
                url = window.createObjectURL(file);
            } else if (window.URL != undefined) { // mozilla(firefox)
                url = window.URL.createObjectURL(file);
            } else if (window.webkitURL != undefined) { // webkit or chrome
                url = window.webkitURL.createObjectURL(file);
            }
            return url;
        }
    });
</script>
</body>
</html>